import { fileURLToPath, URL } from 'url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  base: '/', // 默认路径
  plugins: [vue(), vueJsx()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      '@common': fileURLToPath(new URL('./src/common', import.meta.url)),
      '@components': fileURLToPath(
        new URL('./src/components', import.meta.url)
      ),
      '@assets': fileURLToPath(new URL('./src/assets', import.meta.url)),
      '@business': fileURLToPath(new URL('./src/business', import.meta.url)),
      '@router': fileURLToPath(new URL('./src/router', import.meta.url)),
      '@stores': fileURLToPath(new URL('./src/stores', import.meta.url)),
      '@views': resolve('src/views'),
    },
  },
  server: {
    host: 'localhost',
    port: 3000,
    cors: true,
    https: false,
    open: true,
    proxy: {
      '/short-video-server': {
        target: 'https://test-wjx.xoyo.com', // 实际请求地址
        changeOrigin: true,
        rewrite: (path) => path.replace('^/short-video-server', ''),
      },
    },
  },
})
